package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {
    //查询月初到月底的预约信息
    @Select("SELECT ORDERDATE,NUMBER,RESERVATIONS FROM t_ordersetting WHERE ORDERDATE BETWEEN #{beginDate} and  #{endDate}")
    List<OrderSetting> findSettingDataByYearAndMonth(@Param("beginDate") String beginDate, String endDate);


    //更新当前日期的最大预约人数
    @Update("UPDATE t_ordersetting SET NUMBER = #{number} WHERE  ORDERDATE = #{settingDay}")
    Boolean updateNumberByOrderdate(int number, String settingDay);


    //移动端效验是否已经预约满
    @Select("select count(1) from t_ordersetting where NUMBER > RESERVATIONS and ORDERDATE=#{orderDate}")
    int isOrderOk(@Param("orderDate") String orderDate);

    //移动端更新预约人数表,预约成功，预约人数+1
    @Update("update t_ordersetting set RESERVATIONS = RESERVATIONS+1 where ORDERDATE =#{orderDate}")
    void updateReservationByOrderDate(@Param("orderDate") String orderDate);


    //根据当前日期更新预约表中的预约人数
//    @Update("UPDATE  t_ordersetting SET RESERVATIONS = 0 " +
//            "WHERE ORDERDATE < CURDATE()")
//    void updateOrderSettingByCurdate();

    //根据当前日期删除预约表信息
    @Delete("DELETE FROM t_ordersetting WHERE ORDERDATE < CURDATE()")
    void deleteOrderSettingByCurdate();
}
